<?php

/**
 * Contacto filter form base class.
 *
 * @package    Sanitas
 * @subpackage filter
 * @author     Jose Antonio Sánchez Bedoya
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseContactoFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'nombre'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'primer_apellido'  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'segundo_apellido' => new sfWidgetFormFilterInput(),
      'num_documento'    => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'tipo_documento'   => new sfWidgetFormFilterInput(),
      'telefono'         => new sfWidgetFormFilterInput(),
      'telefono2'        => new sfWidgetFormFilterInput(),
      'tipo_via'         => new sfWidgetFormFilterInput(),
      'direccion'        => new sfWidgetFormFilterInput(),
      'num_via'          => new sfWidgetFormFilterInput(),
      'resto_via'        => new sfWidgetFormFilterInput(),
      'piso'             => new sfWidgetFormFilterInput(),
      'puerta'           => new sfWidgetFormFilterInput(),
      'escalera'         => new sfWidgetFormFilterInput(),
      'portal'           => new sfWidgetFormFilterInput(),
      'municipio'        => new sfWidgetFormFilterInput(),
      'cod_postal'       => new sfWidgetFormFilterInput(),
      'provincia'        => new sfWidgetFormFilterInput(),
      'email'            => new sfWidgetFormFilterInput(),
      'fecha_nac'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'sexo'             => new sfWidgetFormFilterInput(),
      'autoriza'         => new sfWidgetFormFilterInput(),
      'idioma'           => new sfWidgetFormFilterInput(),
      'polizasTotales'   => new sfWidgetFormFilterInput(),
      'polizasBajas'     => new sfWidgetFormFilterInput(),
      'created_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'validated_at'     => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'is_validated'     => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'removed_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'remove_it'        => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'users_list'       => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser')),
      'polizas_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Poliza')),
      'grupos_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Grupo')),
      'my_users_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser')),
    ));

    $this->setValidators(array(
      'nombre'           => new sfValidatorPass(array('required' => false)),
      'primer_apellido'  => new sfValidatorPass(array('required' => false)),
      'segundo_apellido' => new sfValidatorPass(array('required' => false)),
      'num_documento'    => new sfValidatorPass(array('required' => false)),
      'tipo_documento'   => new sfValidatorPass(array('required' => false)),
      'telefono'         => new sfValidatorPass(array('required' => false)),
      'telefono2'        => new sfValidatorPass(array('required' => false)),
      'tipo_via'         => new sfValidatorPass(array('required' => false)),
      'direccion'        => new sfValidatorPass(array('required' => false)),
      'num_via'          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'resto_via'        => new sfValidatorPass(array('required' => false)),
      'piso'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'puerta'           => new sfValidatorPass(array('required' => false)),
      'escalera'         => new sfValidatorPass(array('required' => false)),
      'portal'           => new sfValidatorPass(array('required' => false)),
      'municipio'        => new sfValidatorPass(array('required' => false)),
      'cod_postal'       => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'provincia'        => new sfValidatorPass(array('required' => false)),
      'email'            => new sfValidatorPass(array('required' => false)),
      'fecha_nac'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'sexo'             => new sfValidatorPass(array('required' => false)),
      'autoriza'         => new sfValidatorPass(array('required' => false)),
      'idioma'           => new sfValidatorPass(array('required' => false)),
      'polizasTotales'   => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'polizasBajas'     => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'created_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'validated_at'     => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'is_validated'     => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'removed_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'remove_it'        => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'users_list'       => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser', 'required' => false)),
      'polizas_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Poliza', 'required' => false)),
      'grupos_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Grupo', 'required' => false)),
      'my_users_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('contacto_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addUsersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserContacto UserContacto')
      ->andWhereIn('UserContacto.user_id', $values)
    ;
  }

  public function addPolizasListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.PolizaContacto PolizaContacto')
      ->andWhereIn('PolizaContacto.poliza_id', $values)
    ;
  }

  public function addGruposListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.GrupoContacto GrupoContacto')
      ->andWhereIn('GrupoContacto.grupo_id', $values)
    ;
  }

  public function addMyUsersListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.UserContacto UserContacto')
      ->andWhereIn('UserContacto.user_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Contacto';
  }

  public function getFields()
  {
    return array(
      'id'               => 'Number',
      'nombre'           => 'Text',
      'primer_apellido'  => 'Text',
      'segundo_apellido' => 'Text',
      'num_documento'    => 'Text',
      'tipo_documento'   => 'Text',
      'telefono'         => 'Text',
      'telefono2'        => 'Text',
      'tipo_via'         => 'Text',
      'direccion'        => 'Text',
      'num_via'          => 'Number',
      'resto_via'        => 'Text',
      'piso'             => 'Number',
      'puerta'           => 'Text',
      'escalera'         => 'Text',
      'portal'           => 'Text',
      'municipio'        => 'Text',
      'cod_postal'       => 'Number',
      'provincia'        => 'Text',
      'email'            => 'Text',
      'fecha_nac'        => 'Date',
      'sexo'             => 'Text',
      'autoriza'         => 'Text',
      'idioma'           => 'Text',
      'polizasTotales'   => 'Number',
      'polizasBajas'     => 'Number',
      'created_at'       => 'Date',
      'updated_at'       => 'Date',
      'validated_at'     => 'Date',
      'is_validated'     => 'Boolean',
      'removed_at'       => 'Date',
      'remove_it'        => 'Boolean',
      'users_list'       => 'ManyKey',
      'polizas_list'     => 'ManyKey',
      'grupos_list'      => 'ManyKey',
      'my_users_list'    => 'ManyKey',
    );
  }
}
